package com.lancoo.znbkxx.teacher.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.ClassStuCognitiveHonorRollListInfor
import kotlinx.android.synthetic.main.aibk_adapter_item_honor_roll.view.*
import kotlinx.android.synthetic.main.aibk_include_honor_roll_student_top3.*

class AibkClassStuHonorRollListAdapter(
        val context: Context?,
        val classStuCognitiveHonorRollListInfor: ClassStuCognitiveHonorRollListInfor
): KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        return LayoutInflater.from(context)
                .inflate(R.layout.aibk_adapter_item_honor_roll, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {

        val stuPhotoPath = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[position+3].StuPhotoPath
        val stuName = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[position+3].StuName
        val rzzdGrade = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[position+3].RzzdGrade
        val level = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[position+3].Level
        val cognitiveGradeName = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[position+3].CognitiveGradeName
        val stuScore = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[position+3].StuScore

        //显示名次
        if(position <= 1){
            holder.convertView.IvRankIndex.visibility = View.VISIBLE
            holder.convertView.TvRankIndex.visibility = View.GONE
            if(position == 0) {
                holder.convertView.IvRankIndex.setImageResource(R.mipmap.aibk_icon_head_frame_four)
            }else if(position == 1){
                holder.convertView.IvRankIndex.setImageResource(R.mipmap.aibk_icon_head_frame_five)
            }
        }else{
            holder.convertView.IvRankIndex.visibility = View.GONE
            holder.convertView.TvRankIndex.visibility = View.VISIBLE
            holder.convertView.TvRankIndex.text = (position + 4).toString()
        }

        //显示学生头像和姓名
        Glide.with(context!!).load(stuPhotoPath).into(holder.convertView.CivStuHead );
        holder.convertView.TvStuName.text = stuName

        //是否显示认知等级称号及分数
        if(stuScore < 0) {
            holder.convertView.LlItemPart2.visibility = View.GONE
            holder.convertView.LlItemPart3.visibility = View.VISIBLE
        }else{
            holder.convertView.LlItemPart2.visibility = View.VISIBLE
            holder.convertView.LlItemPart3.visibility = View.GONE

            if(rzzdGrade == 1){
                holder.convertView.IvRankIcon.setImageResource(R.mipmap.aibk_icon_rank_star1)
            }else if(rzzdGrade == 2){
                holder.convertView.IvRankIcon.setImageResource(R.mipmap.aibk_icon_rank_star2)
            }else if(rzzdGrade == 3){
                holder.convertView.IvRankIcon.setImageResource(R.mipmap.aibk_icon_rank_star3)
            }else if(rzzdGrade == 4){
                holder.convertView.IvRankIcon.setImageResource(R.mipmap.aibk_icon_rank_star4)
            }
            holder.convertView.TvRankInfor.text = cognitiveGradeName+"Lv."+rzzdGrade+"-"+level
            holder.convertView.TvCognitiveScore.text = LancooMethod.killlingDouble(stuScore)
        }
    }

    override fun getItemCount(): Int {
        return classStuCognitiveHonorRollListInfor.ClassIndexInfoList.size-3
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

}